import random,  Utilities,  MathGenerator
from Utilities import *
from MathGenerator import *

class Balloon(pygame.sprite.Sprite):
	
    
    def __init__(self, centerpoint, difficulty,  speed):
        pygame.sprite.Sprite.__init__(self)
        self.balloon_size = (110, 200)
        self.balloon_image = load_image(self.selectColor(), -1)
        self.balloon_image = pygame.transform.scale(self.balloon_image,  self.balloon_size)
        self.count = ""
        self.right = 1
        self.a = 0
        self.b = 0
        self.operation = ''
        self.result = 0
        self.get_count(difficulty)
        self.speed = speed
        self.image = pygame.Surface(self.balloon_size,  SRCALPHA,  32)
        self.image.blit(self.balloon_image,  (0, 0))
        self.text1 = ''
        self.text2 = ''
        self.text3 = ''
        self.text4 = ''
        self.font = pygame.font.Font(None,  32)
        self.get_text()
        
        self.operation = self.font.render(self.operation, 1, (0, 0, 0))
        self.image.blit(self.operation,  (20, 30))
        self.image.blit(self.text1,  (40, 20))
        self.image.blit(self.text2,  (40, 40))
        self.image.blit(self.text3,  (30, 60))
        self.image.blit(self.text4,  (40, 80))
        self.image.convert_alpha()
        self.rect = self.image.get_rect()
        self.rect.center = centerpoint
        

    def update(self):
        self.rect.move_ip(0,  -self.speed)
    
    def selectColor(self):
        item = random.randint(1, 10)
        return "balloon" + str(item) + ".png"
        
    def get_count(self,  difficulty):
        isRight = random.random()
        if isRight > 0.5:
            self.a,  self.b,  self.result,  self.operation = generateRight(difficulty)
            if (self.b == 0) and (self.operation == '/'):
                self.right = 0
            else:
                self.right = 1
        else:
            self.a,  self.b,  self.result,  self.operation = generateWrong(difficulty)
            self.right = 0
            
    def get_text(self):
        self.text1 = '    ' + str(self.a)
        if self.a > 10:
            self.text1 =  self.text1[-3:]
        else:
            self.text1 =  self.text1[-4:]
        self.text1 = self.font.render(self.text1, 1, (0, 0, 0))
        
        self.text2 = '    ' + str(self.b)
        if self.b > 10:
            self.text2 =  self.text2[-3:]
        else:
            self.text2 =  self.text2[-4:]
        self.text2 = self.font.render(self.text2, 1, (0, 0, 0))
        
        self.text3 = '-------'
        self.text3 = self.font.render(self.text3, 1, (0, 0, 0))
        
        self.text4 = '    ' + str(self.result)
        if self.result > 10:
            self.text4 =  self.text4[-3:]
        else:
            self.text4 =  self.text4[-4:]
        self.text4 = self.font.render(self.text4, 1, (0, 0, 0))
